<?php

declare(strict_types=1);
/**
 * This file is part of Hyperf.
 *
 * @link     https://www.hyperf.io
 * @document https://hyperf.wiki
 * @contact  group@hyperf.io
 * @license  https://github.com/hyperf/hyperf/blob/master/LICENSE
 */

namespace App\Model;

use Carbon\Carbon;

/**
 * @property int $id
 * @property string $area_name 小区名称
 * @property string $title 房产标题
 * @property int $house_shi 室
 * @property int $house_ting 厅
 * @property int $house_wei 卫
 * @property string $house_about 房产介绍
 * @property string $house_images 房产图片
 * @property int $state 状态：-1取消 0待上架 1已上架 2已成交
 * @property string $phone 联系方式
 * @property string $remark 备注
 * @property Carbon $created_at 创建时间
 * @property int $look_times 带看次数
 * @property int $like_customer 意向人数
 * @property string $house_type
 * @property string $publish_at 发布时间
 * @property string $updated_at 更新时间
 */
class Shoufang extends Model
{
    /**
     * The table associated with the model.
     */
    protected ?string $table = 'shoufang';

    /**
     * The attributes that are mass assignable.
     */
    protected array $fillable = ['id', 'area_name', 'title', 'house_shi', 'house_ting', 'house_wei', 'house_about', 'house_images', 'state', 'phone', 'remark', 'created_at', 'updated_at', 'publish_at', 'look_times', 'like_customer'];

    /**
     * The attributes that should be cast to native types.
     */
    protected array $casts = ['id' => 'integer', 'house_shi' => 'integer', 'house_ting' => 'integer', 'house_wei' => 'integer', 'state' => 'integer', 'created_at' => 'datetime', 'updated_at' => 'datetime', 'look_times' => 'integer', 'like_customer' => 'integer'];

    protected array $appends = ['house_type'];

    public function getHouseTypeAttribute(): string
    {
        return $this->house_shi . '室' . $this->house_ting . '厅' . $this->house_wei . '卫';
    }

    public function getPublishAtAttribute(): string
    {
        $value = $this->attributes['publish_at'];
        return $value ?: '';
    }

    public function getUpdatedAtAttribute(): string
    {
        $value = $this->attributes['updated_at'];
        return $value ?: '';
    }
}
